import { request } from './request';

export async function login(data: any) {
  let res;
  try {
    // 首次请求，cookie中不会携带csrfToken信息，故此处使用try catch 语句，进行两次登录操作
    res = await request('/login', {
      method: 'POST',
      data,
    })
  } catch (error) {
    res = await request('/login', {
      method: 'POST',
      data,
    })
  } finally {
    return res;
  }
}

export async function getTokenInfo() {
  return request('/api/getTokenInfo', {
    method: 'GET',
  })
}

export async function logout() {
  return request('/api/logout', {
    method: 'GET',
  })
}

export default {
  login,
  logout,
  getTokenInfo,
};
